home *** CD-ROM | disk | FTP | other *** search
/ Gekkan Dennou Club 145 / Gekkan Dennou Club - 2000.6 Vol. 145 (Japan).7z / Gekkan Dennou Club - 2000.6 Vol. 145 (Japan) (Track 1).bin / ikap / etc / f56 / f56type.c < prev    next >
C/C++ Source or Header  |  2000-05-08  |  4KB  |  253 lines

  1. /*
  2. 「5x6ドットビットマップフォントを使ってファイル内容をタイプ
  3. */
  4.  
  5. #include    <stdio.h>
  6. #include    <graph.h>
  7.  
  8.  
  9. asm("
  10. _F56pat:
  11.     .INSERT    likap.f56
  12. ");
  13.  
  14. extern    unsigned int    F56pat[];
  15.  
  16.  
  17.  
  18. /*    データゲット
  19.     パターン
  20. */
  21. int    FNTGET56(code,adr)
  22. int    code;
  23. unsigned char *adr;
  24. {
  25.  
  26. typedef    struct    {
  27.     int    start,end;
  28. } CODEBAND;
  29.     int    a,area,cnum;
  30. static    int dbcnt=280;
  31.     
  32.     CODEBAND    codeband[8]={
  33.         { 0x8140, 0x819e },
  34.         { 0x819f, 0x81fc },
  35.         { 0x8240, 0x829e },
  36.         { 0x829f, 0x82fc },
  37.         { 0x8340, 0x839e },
  38.         { 0x839f, 0x83fc },
  39.         { 0x8440, 0x849e },
  40.         { 0x849f, 0x84fc }
  41.     };
  42.  
  43.     for( a=0; a<8; a++ ){
  44.         if( codeband[a].start<=code && code<=codeband[a].end ){
  45.             area=a;
  46.             cnum=code-codeband[a].start;
  47.             if( a%2==0 && (code&0xff)>=0x80 ){
  48.                 cnum-=1;
  49.             }
  50.             goto next;
  51.         }
  52.     }
  53.     area=0;
  54.     cnum=0;
  55. next:
  56.     *(int *)adr=F56pat[area*94+cnum];
  57. //printf("%d/%d\n",area,cnum);
  58. }
  59.  
  60.  
  61.  
  62. /*
  63. addrから格納されている5x6ドットビットマップを指定座標からに表示
  64. */
  65. int    FNTPUT56(fx,fy,addr)
  66. int    fx,fy;
  67. unsigned char *addr;
  68. {
  69.     int    x,y,b,pat;
  70.     pat=*(int *) (addr);
  71.  
  72.     b=31;
  73.     for( y=0; y<6; y++ ){ ; for( x=0; x<5; x++ ){
  74.         if( (pat&(1<<b)) ){
  75.             pset(fx+x,fy+y,0xf);    //
  76.         }
  77.         b--;
  78.     }}
  79.  
  80.     return(0);
  81. }
  82.  
  83.  
  84.  
  85.  
  86. /*
  87. addrから格納されている5x6ドットビットマップを指定座標からに表示
  88. 全部×Nのオーダーで扱う
  89. */
  90. int    FNTPUT56big(fx,fy,addr,N)
  91. int    fx,fy;
  92. unsigned char *addr;
  93. int    N;        //拡大倍率
  94. {
  95.     int    x,y,b,pat;
  96.     pat=*(int *) (addr);
  97.  
  98.     b=31;
  99.     for( y=0; y<6; y++ ){ ; for( x=0; x<5; x++ ){
  100.         if( (pat&(1<<b)) ){
  101. //            pset(fx+x,fy+y,0xf);    //
  102.             fill((fx+x)*N,(fy+y)*N,(fx+x+1)*N-1,(fy+y+1)*N-1,0x0f);    //
  103.         }
  104.         b--;
  105.     }}
  106.  
  107.     return(0);
  108. }
  109.  
  110.  
  111.  
  112.  
  113.  
  114.  
  115.  
  116. /*    タブスペース変換:変換後のバイト数を返す
  117.  
  118. 0d,0aとばす
  119.  
  120. */
  121. int    detab(src,dest)
  122. unsigned char *src,*dest;
  123. {
  124.     unsigned char *s,*d;
  125.     short    x,i,m;
  126.     
  127.     s=src;
  128.     d=dest;
  129.     x=0;
  130.     while( *s ){
  131.         switch( *s ){
  132.             case '\t':
  133.                 m=x%8;
  134.                 if( m==0 ){ m=8; }
  135.                 for( i=0; i<m; i++ ){
  136.                     *d++=' ';
  137.                     x++;
  138.                 }
  139.             break;
  140.             case '\x0d':
  141.             case '\x0a':
  142.                 ;//とばし
  143.             break;
  144.             default:
  145.                 *d++=*s;
  146.                 x++;
  147.             break;
  148.         }
  149.         s++;
  150.     }
  151.     *d=0;
  152.  
  153.     return(x);
  154. }
  155.  
  156.  
  157.  
  158. int    main(argc,argv)
  159. int    argc;
  160. char    *argv[];
  161. {
  162. #define    BUFSIZE    (256)
  163.     unsigned char    srcbuf[BUFSIZE],destbuf[BUFSIZE];    //@@いいかげん
  164.     unsigned char    typefile[128];
  165.     int    x,y,xlen,w,px;
  166.     FILE    *fp;
  167. //    int    swidth=96,sheight=72;    //F502i
  168.     int    swidth=32,sheight=32;    //ぽけすて
  169.     int    drawoffset_x=0,drawoffset_y=16;    //描画開始位置
  170.     int    N=4;                //拡大率
  171.     int    ac;
  172.     int    code;
  173.     unsigned char fntbuf[4];
  174.  
  175.     
  176.     for( ac=1; ac<argc; ac++ ){
  177.         if( argv[ac][0]=='/' || argv[ac][0]=='-' ){ ; switch( argv[ac][1] ){
  178.             case 'w': case 'W':
  179.                 sscanf(&argv[ac][2],"%d,%d",&swidth,&sheight);
  180.             break;
  181.             case 'o': case 'O':
  182.                 sscanf(&argv[ac][2],"%d,%d",&drawoffset_x,&drawoffset_y);
  183.             break;
  184.             case 'b': case 'B':
  185.                 sscanf(&argv[ac][2],"%d",&N);
  186.             break;
  187.         }}
  188.         else{
  189.             //オープンファイル名
  190.             strcpy(typefile,argv[ac]);
  191.         }
  192.     }
  193.     
  194.  
  195.     screen(2,0,1,1);
  196.     window(0,0,767,511);
  197.     apage(0);
  198.     vpage(0xf);
  199.     {
  200.         fp=fopen(typefile,"rt");
  201.         if( fp==NULL ){
  202.             printf(
  203.             "5x6ドットフォントを使ったテキストファイル表示(type)\n"
  204.             "usage : f56type typefile [option]\n"
  205.             "option: /Ww,h 表示領域サイズの設定(def:/W32,32)\n"
  206.             "      : /Ox,y 描画開始位置の設定(def:/O0,16)\n"
  207.             "      : /Bn    拡大表示(def=4:0の時拡大表示なし)\n"
  208.             );
  209.             goto quick_exit;
  210.         }
  211.     }
  212.     x=0;
  213.     y=0;
  214.     while( feof(fp)==0 ){
  215.         fgets(srcbuf,BUFSIZE,fp);
  216.         if( srcbuf[0]=='\n' ){
  217.             goto next;
  218.         }
  219.         xlen=detab(srcbuf,destbuf);
  220.         x=0;
  221.         px=0;
  222.         while(1){
  223.             for( px=0; px<(swidth-6); ){
  224.                 if( destbuf[x]==0 ){ goto next; }
  225.                 if( 0x81<=destbuf[x] && destbuf[x]<=0x84 ){
  226.                     code=0;
  227.                     code=(destbuf[x]<<8)|destbuf[x+1];
  228.                     x++;
  229.                     FNTGET56(code,fntbuf);
  230.                     FNTPUT56(px+drawoffset_x,y*7+drawoffset_y,fntbuf);
  231.                     if( N ){ FNTPUT56big(px+drawoffset_x,y*7+drawoffset_y,fntbuf,N); }
  232.                 }
  233.                 px+=6;
  234.                 x++;
  235.             }
  236.             if( destbuf[x]==0 ){ break; }
  237.             y++;
  238.             if( y>=(sheight/7) ){ break; }
  239.         }
  240. next:
  241.         y++;
  242.         if( y>=(sheight/7) ){ break; }
  243.     }
  244.     {
  245.         fclose(fp);
  246.     }
  247.  
  248. quick_exit:
  249.     return(0);
  250. }
  251.  
  252.  
  253.